package net.hn.hnms.sys.file.api;

import io.swagger.annotations.ApiParam;
import net.hn.hnms.biz.api.feign.base.FeignClientsConfigurationCustom;
import net.hn.hnms.sys.common.core.constant.ServiceNameConstants;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.exception.ServiceException;
import net.hn.hnms.sys.file.api.domain.SysFile;
import net.hn.hnms.sys.file.api.domain.vo.SysOssVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 文件服务
 *
 * @author Lion Li
 */
@FeignClient(contextId = "RemoteFileService", value = ServiceNameConstants.FILE_SERVICE, configuration = FeignClientsConfigurationCustom.class)
public interface RemoteFileService {

    /**
     * 上传文件
     *
     * @param file 文件信息
     * @return 结果
     */
    @PostMapping(value = "/file/OSS_Upload")
    SysFile upload(@RequestParam("name") String name,
                   @RequestParam("originalFilename") String originalFilename,
                   @RequestParam("contentType") String contentType,
                   @RequestParam("file") byte[] file) throws ServiceException;

    /**
     * 删除文件
     *
     * @param ossIds 文件Id
     * @return 结果
     */
    @DeleteMapping(value = "/file/{ossIds}")
    R<Void> remove(@PathVariable(value = "ossIds") Long[] ossIds);

    /**
     * 查询OSS对象基于id串
     */
    @GetMapping(value = "/file/listByIds/{ossIds}")
    R<List<SysOssVo>> listByIds(@ApiParam("OSS对象ID串")
                                @NotEmpty(message = "主键不能为空")
                                @PathVariable(value = "ossIds") Long[] ossIds);
}